package com.bases {
	import flash.display.DisplayObject;
	import flash.display.Sprite;

	public class TUIComponent extends Sprite {
		protected var w:Number = 0;
		protected var h:Number = 0;
		
		/**是否已经销毁过,如果销毁过,就不在销毁*/
		protected var isDispose:Boolean = false;

		public function TUIComponent(){
			super();  //super对父类的引用，不能在静态方法中使用
		}

		/**
		 * 添加多个显示对象
		 * @param childs
		 */
		public function addChilds(... childs):void {
			for (var i:int = 0; i < childs.length; i++){
				this.addChild(childs[i]);
			}
		}

		/**
		 * 移除多个显示对象
		 * @param childs
		 *
		 */
		public function removeChilds(... childs):void {
			for (var i:int = 0; i < childs.length; i++){
				this.removeChild(childs[i]);
			}
		}

		/**
		 * @param w
		 * @param h
		 */
		public function setSize(w:Number, h:Number):void {
			this.width = w;
			this.height = h;
		}

		/**
		 * 设置位置
		 * @param x
		 * @param y
		 *
		 */
		public function setPos(x:Number, y:Number):void {
			this.x = x;
			this.y = y;
		}

		protected function relayout():void {
		}

		/**
		 * 移除对象,销毁对象
		 */
		public function dispose():void {
			if (!this.isDispose){
				this.isDispose = true;
				this.removeAllChildren();
			}
		}

		/**
		 * 移除所有显示对象
		 * 释入对象
		 */
		public function removeAllChildren():void {
			while (this.numChildren > 0){
				var del:DisplayObject = this.removeChildAt(0); //返回移除的对象
				if ((del as TUIComponent) != null){
					(del as TUIComponent).dispose();
				}
				del = null;
			}
		}
	}
}